﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace Ecobee.Net
{
	public class Alert : ApiObject
	{
		private string _acknowledgeRef = string.Empty;
		private DateTime? _date = null;
		private Time _time = null;
		private string _severity = string.Empty;
		private string _text = string.Empty;
		private int _alertNumber = 0;
		private string _alertType = string.Empty;
		private bool _isOperatorAlert = false;
		private string _reminder = string.Empty;
		private bool _showIdt = false;
		private bool _showWeb = false;
		private bool _sendEmail = false;
		private string _acknowledgement = string.Empty;
		private bool _remindMeLater = false;
		private string _thermostatIdentifier = string.Empty;

		public string AcknowledgeRef
		{
			get
			{
				return _acknowledgeRef;
			}
			set
			{
				this.SetProperty(ref _acknowledgeRef, value);
			}
		}

		public DateTime? Date
		{
			get
			{
				return _date;
			}
			set
			{
				_date = value;
			}
		}

		public Time Time
		{
			get
			{
				return _time;
			}
			set
			{
				_time = value;
			}
		}

		public string Severity
		{
			get
			{
				return _severity;
			}
			set
			{
				_severity = value;
			}
		}

		public string Text
		{
			get
			{
				return _text;
			}
			set
			{
				_text = value;
			}
		}

		public int AlertNumber
		{
			get
			{
				return _alertNumber;
			}
			set
			{
				_alertNumber = value;
			}
		}

		public string AlertType
		{
			get
			{
				return _alertType;
			}
			set
			{
				_alertType = value;
			}
		}

		public bool IsOperatorAlert
		{
			get
			{
				return _isOperatorAlert;
			}
			set
			{
				_isOperatorAlert = value;
			}
		}

		public string Reminder
		{
			get
			{
				return _reminder;
			}
			set
			{
				_reminder = value;
			}
		}

		public bool ShowIdt
		{
			get
			{
				return _showIdt;
			}
			set
			{
				_showIdt = value;
			}
		}

		public bool ShowWeb
		{
			get
			{
				return _showWeb;
			}
			set
			{
				_showWeb = value;
			}
		}

		public bool SendEmail
		{
			get
			{
				return _sendEmail;
			}
			set
			{
				_sendEmail = value;
			}
		}

		public string Acknowledgement
		{
			get
			{
				return _acknowledgement;
			}
			set
			{
				_acknowledgement = value;
			}
		}

		public bool RemindMeLater
		{
			get
			{
				return _remindMeLater;
			}
			set
			{
				_remindMeLater = value;
			}
		}

		public string ThermostatIdentifier
		{
			get
			{
				return _thermostatIdentifier;
			}
			set
			{
				_thermostatIdentifier = value;
			}
		}

		public DateTime DateTimeStamp
		{
			get
			{
				DateTime returnValue = DateTime.Now;

				if (this.Date.HasValue)
				{
					returnValue = this.Date.Value.Add(this.Time);
				}

				return returnValue;
			}
		}

		protected override void OnFromDataObject(dynamic dataObject)
		{
			this.AcknowledgeRef = dataObject.acknowledgeRef;
			this.Date = dataObject.date;
			this.Time = ((JValue)dataObject.time).Value<string>();
			this.Severity = dataObject.severity;
			this.Text = dataObject.text;
			this.AlertNumber = dataObject.alertNumber;
			this.AlertType = dataObject.alertType;
			this.IsOperatorAlert = dataObject.isOperatorAlert;
			this.Reminder = dataObject.reminder;
			this.ShowIdt = dataObject.showIdt;
			this.ShowWeb = dataObject.showWeb;
			this.SendEmail = dataObject.sendEmail;
			this.Acknowledgement = dataObject.acknowledgement;
			this.RemindMeLater = dataObject.remindMeLater;
			this.ThermostatIdentifier = dataObject.thermostatIdentifier;
		}

		protected override string OnUniqueKey()
		{
			return this.AcknowledgeRef;
		}

		protected override string OnGetKeyValue(dynamic dataObject)
		{
			return dataObject.acknowledgeRef;
		}
	}
}
